#!/usr/bin/env bash

ROOT=~/data/YLIMED/mp4_short_encode
TrainSplit=$ROOT/YLIMED_short_mp4_EvAll_split_train.txt
TestSplit=$ROOT/YLIMED_short_mp4_EvAll_split_test.txt
PosValSplit=$ROOT/YLIMED_short_mp4_Ev101_110_split_val.txt
DEVTrainSplit=$ROOT/YLIMED_short_mp4_EvAll_split_train_dev.txt
DEVTestSplit=$ROOT/YLIMED_short_mp4_EvAll_split_test_dev.txt
TOYSplit=$ROOT/YLIMED_short_mp4_EvAll_split_test_toy.txt

# coviar_lstm00  coviar_lstmlrx10  coviar_freezeCNN_lstm  coviar_freezeCNN_lstmlrx10
# coviar_lstmlrx10 mv_res_resnet50
NAME=$1

if [ $1 == "dev" ]
then
    NAME=dev
    LOG=./out/$NAME/log
    MODEL=./out/$NAME/weights

    CUDA_VISIBLE_DEVICES=0,1,2,3 \
    python train.py --arch resnet18 --data-name ylimed \
        --data-root  $ROOT \
        --train-list $TrainSplit \
        --test-list  $PosValSplit \
        --representation mv \
        --model-prefix $MODEL/ylimed \
        --lr      0.005 \
        --lstm_lr 0.005 \
        --hidden_size 512 \
        --batch-size 64 \
        --lr-steps 80 150 200 \
        --epochs 230 \
        --num_segments 5

    # echo "develop"
    # CUDA_VISIBLE_DEVICES=0,1,2,3 \
    # /usr/bin/time -f "\t%E real,\t%U user,\t%S sys" \
    # python train.py --arch resnet152 --data-name ylimed \
    #     --data-root  $ROOT \
    #     --train-list $TOYSplit \
    #     --test-list  $TOYSplit \
    #     --representation iframe \
    #     --model-prefix $MODEL/ylimed \
    #     --lr      0.0003 \
    #     --lstm_lr 0.0003 \
    #     --batch-size 4 \
    #     --lr-steps 40 80 100 \
    #     --epochs 120 \
    #     --gpus 0
    # exit

    # CUDA_VISIBLE_DEVICES=0,1,2,3 \
    # /usr/bin/time -f "\t%E real,\t%U user,\t%S sys" \
    # python train.py --lr 0.005 --batch-size 4 --arch resnet50 \
    #     --data-name ylimed --representation mv \
    #     --data-root $ROOT \
    #     --train-list $TOYSplit \
    #     --test-list $TOYSplit  \
    #     --model-prefix ylimed_toy \
    #     --lr-steps 80 150 200 \
    #     --epochs 230 \
    #     --gpus 0 \
    #     # --freeze \
    #     # --weights $CoViAR_MODEL/ylimed_mv_model_best.pth.tar
    #     # > $LOG/ylimed_mv_model.out 2>&1
    # set +x
    # exit

elif [ $1 == "buf" ]
then
    CUDA_VISIBLE_DEVICES=0,1,2,3 \
    python train.py --arch resnet101 --data-name ylimed \
        --data-root  $ROOT \
        --train-list $TrainSplit \
        --test-list  $PosValSplit \
        --representation mv \
        --model-prefix $MODEL/ylimed \
        --lr      0.005 \
        --lstm_lr 0.005 \
        --batch-size 45 \
        --lr-steps 80 120 \
        --epochs 160 \
        --gpus 0 1 #> $LOG/ylimed_mv_model.out 2>&1 &
    # Note: 1和>之间需要空格
elif [ $1 == "lstm-resnet50" ]
then
    set -x
    CUDA_VISIBLE_DEVICES=0,1,2,3 \
    python train.py --arch resnet50 --data-name ylimed \
        --data-root  $ROOT \
        --train-list $TrainSplit \
        --test-list  $PosValSplit \
        --representation mv \
        --model-prefix $MODEL/ylimed \
        --lr      0.005 \
        --lstm_lr 0.005 \
        --batch-size 64 \
        --lr-steps 80 150 200 \
        --epochs 230 \
        --gpus 0 1 > $LOG/ylimed_mv_model.out 2>&1 &
    # Note: 1和>之间需要空格

    CUDA_VISIBLE_DEVICES=2,3 \
    python train.py --arch resnet50 --data-name ylimed \
        --data-root  $ROOT \
        --train-list $TrainSplit \
        --test-list  $PosValSplit \
        --representation residual \
        --model-prefix $MODEL/ylimed \
        --lr      0.001 \
        --lstm_lr 0.001 \
        --batch-size 64 \
        --lr-steps 80 120 180 \
        --epochs 200 \
        --gpus 0 1 > $LOG/ylimed_residual_model.out 2>&1 &
    set +x

elif [ $1 == "freeze_cnn-lstm" ]
then
    echo "freeze_cnn-lstm ylimed I S: $(date "+%Y-%m-%d %H:%M:%S")"
    set -x
    CUDA_VISIBLE_DEVICES=0,1,2,3 \
    /usr/bin/time -f "\t%E real,\t%U user,\t%S sys" \
    python train.py --arch resnet152 --data-name ylimed \
        --data-root  $ROOT \
        --train-list $TrainSplit \
        --test-list  $PosValSplit \
        --representation iframe \
        --model-prefix $MODEL/ylimed \
        --lr      0.0003 \
        --lstm_lr 0.0003 \
        --batch-size 32 \
        --lr-steps 40 80 100 \
        --epochs 120 \
        --freeze \
        --weights $CoViAR_MODEL/ylimed_iframe_model_best.pth.tar \
        --gpus 0 1 > $LOG/ylimed_iframe_model.out 2>&1 &
    set +x

    echo "freeze_cnn-lstm ylimed M S: $(date "+%Y-%m-%d %H:%M:%S")"
    set -x
    CUDA_VISIBLE_DEVICES=2,3 \
    /usr/bin/time -f "\t%E real,\t%U user,\t%S sys" \
    python train.py --arch resnet18 --data-name ylimed \
        --data-root  $ROOT \
        --train-list $TrainSplit \
        --test-list  $PosValSplit \
        --representation mv \
        --model-prefix $MODEL/ylimed \
        --lr      0.005 \
        --lstm_lr 0.005 \
        --batch-size 80 \
        --lr-steps 80 150 200 \
        --epochs 230 \
        --freeze \
        --weights $CoViAR_MODEL/ylimed_mv_model_best.pth.tar \
        --gpus 0 > $LOG/ylimed_mv_model.out 2>&1 &
    set +x

    echo "freeze_cnn-lstm ylimed R S: $(date "+%Y-%m-%d %H:%M:%S")"
    set -x
    CUDA_VISIBLE_DEVICES=3 \
    /usr/bin/time -f "\t%E real,\t%U user,\t%S sys" \
    python train.py --arch resnet18 --data-name ylimed \
        --data-root  $ROOT \
        --train-list $TrainSplit \
        --test-list  $PosValSplit \
        --representation residual \
        --model-prefix $MODEL/ylimed \
        --lr      0.001 \
        --lstm_lr 0.001 \
        --batch-size 80 \
        --lr-steps 80 120 180 \
        --epochs 200 \
        --freeze \
        --weights $CoViAR_MODEL/ylimed_residual_model_best.pth.tar \
        --gpus 0 > $LOG/ylimed_residual_model.out 2>&1 &
    set +x

else
    echo "Please make sure the positon variable is ..."
fi
